package com.lkxx;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.lkxx.entity.*;
import com.lkxx.entity.handler.IntToStringWriterHandler;
import com.lkxx.entity.listener.InstallAccomplishListener;
import com.lkxx.entity.listener.InstallUnfinishedListener;
import com.lkxx.entity.listener.MalfunctionTemplateListener;
import com.lkxx.entity.listener.SubstationListener;
import com.lkxx.entity.util.ExcelMergeUtil;
import com.lkxx.entity.vo.ExportExcelVoByAccomplish;
import com.lkxx.entity.vo.ExportExcelVoByUnfinished;
import com.lkxx.entity.vo.ExportExcelVoFA;
import com.lkxx.entity.vo.ExportExcelVoFU;
import javafx.application.Application;
import javafx.scene.AccessibleAction;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;

import java.awt.*;
import java.io.File;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: lkxx [mazhenjun.lk.xx@gmail.com]
 * @CreateTime: 2023-10-31  16:51
 * @Description: TODO
 * @Version: 1.0
 */
public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        BorderPane root = new BorderPane();
        Button importButton = new Button("导入Excel文件");

        importButton.setOnAction(e -> {
            FileChooser fileChooser = new FileChooser();
            fileChooser.setInitialDirectory(new File("C:\\Users\\Administrator\\Desktop\\"));
            List<File> files = fileChooser.showOpenMultipleDialog(primaryStage);
            DataRoot dataRoot = processData(files);
            Label label = new Label();
            label.setText("故障竣工数量：" + dataRoot.getMalfunctionAccomplishList().size() + "\n" +
                    "新装竣工数量：" + dataRoot.getInstallAccomplishList().size() + "\n" +
                    "故障在途数量：" + dataRoot.getMalfunctionUnfinishedList().size() + "\n" +
                    "新装在途数量：" + dataRoot.getInstallUnfinishedList().size() + "\n" +
                    "支局对照表：" + dataRoot.getSubstationList().size() + "\n" +
                    "------- 正在急速处理中 -------");

            List<Substation> substationList = dataRoot.getSubstationList();

            root.setCenter(label);

            // 将竣工与在途进行数据处理
            // 新装竣工昨日数据
            List<InstallAccomplish> installAccomplishList = processInstallAccomplishData(dataRoot.getInstallAccomplishList());
            // 故障竣工昨日数据
            List<MalfunctionTemplate> malfunctionAccomplishList = processMalfunctionAccomplishData(dataRoot.getMalfunctionAccomplishList());
            // 新装在途的所有工单
            List<InstallUnfinished> installUnfinishedList = processInstallUnfinishedData(dataRoot.getInstallUnfinishedList());
            // 故障在途的所有工单
            List<MalfunctionTemplate> malfunctionUnfinishedList = processMalfunctionUnfinishedData(dataRoot.getMalfunctionUnfinishedList());

            Label resultCount = new Label();
            resultCount.setText("------- 数据筛选完毕, 准备统计 -------");
            root.setCenter(resultCount);

            // 获取竣工数据统计
            List<ExportExcelVoByAccomplish> exportExcelVoByAccomplishList = getCountByAccomplish(installAccomplishList, malfunctionAccomplishList);
            exportExcelVoByAccomplishList.forEach(a -> {
                if (a.getProcessPerson() != null) {
                    substationList.forEach(b -> {
                        if (a.getProcessPerson().equals(b.getSubstation())) {
                            a.setSubStationName(b.getName());
                        }
                    });
                }
                if (a.getSubStationName() == null) {
                    a.setSubStationName("其他");
                }
            });
            // 对竣工数据的总计升级排序
            List<ExportExcelVoByAccomplish> accomplishFinalResult = new ArrayList<>();
            Map<String, List<ExportExcelVoByAccomplish>> accomplishResult = exportExcelVoByAccomplishList.stream().filter(a -> !"其他".equals(a.getSubStationName())).collect(Collectors.groupingBy(ExportExcelVoByAccomplish::getSubStationName));
            for (Map.Entry<String, List<ExportExcelVoByAccomplish>> stringListEntry : accomplishResult.entrySet()) {
                List<ExportExcelVoByAccomplish> collect = stringListEntry.getValue().stream().sorted(Comparator.comparing(ExportExcelVoByAccomplish::getCount)).collect(Collectors.toList());
                if (!"其他".equals(stringListEntry.getKey())) {
                    accomplishFinalResult.addAll(collect);
                }
            }

            // 增加统计行数据
            accomplishFinalResult = addAccomplishCountData(accomplishFinalResult);
//            accomplishFinalResult.add(exportExcelVoByAccomplishList.stream().filter(a -> "总计".equals(a.getSubStationName())).collect(Collectors.toList()).get(0));


            // ======================================================================================================================================================================================== //


            // 获取在途数据统计
            List<ExportExcelVoByUnfinished> exportExcelVoByUnfinishedList = getCountByUnfinished(installUnfinishedList, malfunctionUnfinishedList);
            exportExcelVoByUnfinishedList.forEach(a -> {
                if (a.getProcessPerson() != null) {
                    substationList.forEach(b -> {
                        if (a.getProcessPerson().equals(b.getSubstation())) {
                            a.setSubStationName(b.getName());
                        }
                    });
                }
                if (a.getSubStationName() == null) {
                    a.setSubStationName("其他");
                }
            });
            List<ExportExcelVoByUnfinished> unfinishedFinalResult = new ArrayList<>();
            Map<String, List<ExportExcelVoByUnfinished>> unfinishedResult = exportExcelVoByUnfinishedList.stream().filter(a -> !"其他".equals(a.getSubStationName())).collect(Collectors.groupingBy(ExportExcelVoByUnfinished::getSubStationName));
            for (Map.Entry<String, List<ExportExcelVoByUnfinished>> stringListEntry : unfinishedResult.entrySet()) {
                List<ExportExcelVoByUnfinished> collect = stringListEntry.getValue().stream().sorted(Comparator.comparing(ExportExcelVoByUnfinished::getCount)).collect(Collectors.toList());
                if (!"其他".equals(stringListEntry.getKey())) {
                    unfinishedFinalResult.addAll(collect);
                }
            }
//            unfinishedFinalResult.add(exportExcelVoByUnfinishedList.stream().filter(a -> "总计".equals(a.getSubStationName())).collect(Collectors.toList()).get(0));
            // 增加统计行数据
            unfinishedFinalResult = addUnfinishedCountData(unfinishedFinalResult);

            Label dataCount = new Label();
            dataCount.setText("------- 数据统计完毕, 准备导出... -------");
            root.setCenter(dataCount);

            String fileName = "C:\\Users\\Administrator\\Desktop\\" + DateUtil.format(new Date(), "yyyy-MM-dd") + "_" + System.currentTimeMillis() + ".xls";


            WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
            WriteCellStyle headWriteCellStyle = new WriteCellStyle();
            // 标题字体大小
            WriteFont contentWriteFont = new WriteFont();
            contentWriteFont.setFontHeightInPoints((short) 12);
            headWriteCellStyle.setWriteFont(contentWriteFont);
            //标题黄色底纹
            headWriteCellStyle.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex());

            //边框
            contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);
            contentWriteCellStyle.setBorderLeft(BorderStyle.THIN);
            contentWriteCellStyle.setBorderRight(BorderStyle.THIN);
            contentWriteCellStyle.setBorderTop(BorderStyle.THIN);
            // 水平居中
            contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
            // 垂直居中
            contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            // 设置自动换行，前提内容中需要加「\n」才有效
            contentWriteCellStyle.setWrapped(true);
            //初始化样式
            HorizontalCellStyleStrategy horizontalCellStyleStrategy =
                    new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);

            //合并单元格所需参数
            //合并坐标
            int[] mergeColumeIndex = {1,0};
            // 从第二行后开始合并
            int mergeRowIndex = 1;
            // 这里 指定文件
            try (ExcelWriter excelWriter = EasyExcel.write(fileName).build()) {
                WriteSheet writeSheet = EasyExcel.writerSheet(0, "竣工数据统计").head(ExportExcelVoByAccomplish.class)
                        .registerWriteHandler(horizontalCellStyleStrategy)
                        .registerWriteHandler(new IntToStringWriterHandler())
                        .registerWriteHandler(new ExcelMergeUtil(mergeRowIndex, mergeColumeIndex))
                        .build();
                excelWriter.write(accomplishFinalResult, writeSheet);

                WriteSheet writeSheet1 = EasyExcel.writerSheet(1, "在途数据统计").head(ExportExcelVoByUnfinished.class)
                        .registerWriteHandler(horizontalCellStyleStrategy)
                        .registerWriteHandler(new IntToStringWriterHandler())
                        .registerWriteHandler(new ExcelMergeUtil(mergeRowIndex, mergeColumeIndex))
                        .build();
                excelWriter.write(unfinishedFinalResult, writeSheet1);
            }

            Label over = new Label();
            over.setText("------- 数据导出完毕, 请在桌面查看~~ -------");
            root.setCenter(over);

//            System.out.println("竣工数据统计：");
//            System.out.println(exportExcelVoByAccomplishList);
//
//            System.out.println("==================");
//            System.out.println("在途数据统计: ");
//            System.out.println(exportExcelVoByUnfinishedList);

        });

        root.setCenter(importButton);
        Scene scene = new Scene(root);
        primaryStage.setScene(scene);
        primaryStage.setWidth(285);
        primaryStage.setHeight(215);
        primaryStage.setTitle("Lkxx-easy-work");
        primaryStage.show();
    }

    private List<ExportExcelVoByUnfinished> addUnfinishedCountData(List<ExportExcelVoByUnfinished> unfinishedFinalResult) {
        ExportExcelVoByUnfinished e = new ExportExcelVoByUnfinished();
        e.setSubStationName("总计");
        e.setXinzhuang(unfinishedFinalResult.stream().map(ExportExcelVoByUnfinished::getXinzhuang).reduce(0, Integer::sum));
        e.setXiugaichanpinshuxing(unfinishedFinalResult.stream().map(ExportExcelVoByUnfinished::getXiugaichanpinshuxing).reduce(0, Integer::sum));
        e.setYijibugaihao(unfinishedFinalResult.stream().map(ExportExcelVoByUnfinished::getYijibugaihao).reduce(0, Integer::sum));
        e.setGuzhang(unfinishedFinalResult.stream().map(ExportExcelVoByUnfinished::getGuzhang).reduce(0, Integer::sum));
        e.setGaisulv(unfinishedFinalResult.stream().map(ExportExcelVoByUnfinished::getGaisulv).reduce(0, Integer::sum));
        e.setCount(unfinishedFinalResult.stream().map(ExportExcelVoByUnfinished::getCount).reduce(0, Integer::sum));
        unfinishedFinalResult.add(e);
        return unfinishedFinalResult;
    }

    private List<ExportExcelVoByAccomplish> addAccomplishCountData(List<ExportExcelVoByAccomplish> accomplishFinalResult) {
        ExportExcelVoByAccomplish e = new ExportExcelVoByAccomplish();
        e.setSubStationName("总计");
        e.setXinzhuang(accomplishFinalResult.stream().map(ExportExcelVoByAccomplish::getXinzhuang).reduce(0, Integer::sum));
        e.setXiugaichanpinshuxing(accomplishFinalResult.stream().map(ExportExcelVoByAccomplish::getXiugaichanpinshuxing).reduce(0, Integer::sum));
        e.setYijibugaihao(accomplishFinalResult.stream().map(ExportExcelVoByAccomplish::getYijibugaihao).reduce(0, Integer::sum));
        e.setGuzhang(accomplishFinalResult.stream().map(ExportExcelVoByAccomplish::getGuzhang).reduce(0, Integer::sum));
        e.setGaisulv(accomplishFinalResult.stream().map(ExportExcelVoByAccomplish::getGaisulv).reduce(0, Integer::sum));
        e.setCount(accomplishFinalResult.stream().map(ExportExcelVoByAccomplish::getCount).reduce(0, Integer::sum));
        accomplishFinalResult.add(e);

        return accomplishFinalResult;
    }

    private List<ExportExcelVoByUnfinished> getCountByUnfinished(List<InstallUnfinished> installUnfinishedList, List<MalfunctionTemplate> malfunctionUnfinishedList) {
        List<ExportExcelVoByUnfinished> result = new ArrayList<>();
        // 新装竣工通过人名分组
        Map<String, List<InstallUnfinished>> install = installUnfinishedList.stream().collect(Collectors.groupingBy(InstallUnfinished::getThisProcessPerson));
        // 故障竣工通过人名分组
        Map<String, List<MalfunctionTemplate>> malfunction = malfunctionUnfinishedList.stream().collect(Collectors.groupingBy(MalfunctionTemplate::getPrincipal));

        for (Map.Entry<String, List<InstallUnfinished>> stringListEntry : install.entrySet()) {
            ExportExcelVoByUnfinished exportExcelVoByUnfinished = new ExportExcelVoByUnfinished();
            exportExcelVoByUnfinished.setProcessPerson(stringListEntry.getKey());
            List<InstallUnfinished> value = stringListEntry.getValue();
            for (InstallUnfinished installUnfinished : value) {
                switch (installUnfinished.getType()) {
                    case "新装":
                        exportExcelVoByUnfinished.setXinzhuang(exportExcelVoByUnfinished.getXinzhuang() + 1);
                        break;
                    case "修改产品属性":
                        exportExcelVoByUnfinished.setXiugaichanpinshuxing(exportExcelVoByUnfinished.getXiugaichanpinshuxing() + 1);
                        break;
                    case "移机不改号":
                        exportExcelVoByUnfinished.setYijibugaihao(exportExcelVoByUnfinished.getYijibugaihao() + 1);
                        break;
                    case "改速率":
                        exportExcelVoByUnfinished.setGaisulv(exportExcelVoByUnfinished.getGaisulv() + 1);
                        break;
                }
            }
            List<MalfunctionTemplate> malfunctionTemplateList = malfunction.get(stringListEntry.getKey());
            if (malfunctionTemplateList == null || malfunctionTemplateList.isEmpty()) {
                exportExcelVoByUnfinished.setGuzhang(0);
            } else {
                exportExcelVoByUnfinished.setGuzhang(malfunctionTemplateList.size());
            }
            int count = exportExcelVoByUnfinished.getYijibugaihao() + exportExcelVoByUnfinished.getGaisulv() + exportExcelVoByUnfinished.getXiugaichanpinshuxing() + exportExcelVoByUnfinished.getXinzhuang()
                    + exportExcelVoByUnfinished.getGuzhang();
            exportExcelVoByUnfinished.setCount(count);
            result.add(exportExcelVoByUnfinished);
            malfunction.remove(stringListEntry.getKey());
        }

        if (!malfunction.isEmpty()) {
            for (Map.Entry<String, List<MalfunctionTemplate>> stringListEntry : malfunction.entrySet()) {
                ExportExcelVoByUnfinished exportExcelVoByUnfinished = new ExportExcelVoByUnfinished();
                exportExcelVoByUnfinished.setProcessPerson(stringListEntry.getKey());
                List<MalfunctionTemplate> value = stringListEntry.getValue();
                exportExcelVoByUnfinished.setGuzhang(value.size());
                int count = exportExcelVoByUnfinished.getYijibugaihao() + exportExcelVoByUnfinished.getXiugaichanpinshuxing() + exportExcelVoByUnfinished.getXinzhuang()
                        + exportExcelVoByUnfinished.getGuzhang();
                exportExcelVoByUnfinished.setCount(count);
                result.add(exportExcelVoByUnfinished);
            }
        }
        return result;
    }

    private List<ExportExcelVoByAccomplish> getCountByAccomplish(List<InstallAccomplish> installAccomplishList, List<MalfunctionTemplate> malfunctionAccomplishList) {
        List<ExportExcelVoByAccomplish> result = new ArrayList<>();
        // 新装竣工通过人名分组
        Map<String, List<InstallAccomplish>> install = installAccomplishList.stream().collect(Collectors.groupingBy(InstallAccomplish::getThisProcessPerson));
        // 故障竣工通过人名分组
        Map<String, List<MalfunctionTemplate>> malfunction = malfunctionAccomplishList.stream().collect(Collectors.groupingBy(MalfunctionTemplate::getPrincipal));

        for (Map.Entry<String, List<InstallAccomplish>> stringListEntry : install.entrySet()) {
            ExportExcelVoByAccomplish exportExcelVoByAccomplish = new ExportExcelVoByAccomplish();
            exportExcelVoByAccomplish.setProcessPerson(stringListEntry.getKey());
            List<InstallAccomplish> value = stringListEntry.getValue();
            for (InstallAccomplish installAccomplish : value) {
                switch (installAccomplish.getType()) {
                    case "新装":
                        exportExcelVoByAccomplish.setXinzhuang(exportExcelVoByAccomplish.getXinzhuang() + 1);
                        break;
                    case "改速率":
                        exportExcelVoByAccomplish.setGaisulv(exportExcelVoByAccomplish.getGaisulv() + 1);
                        break;
                    case "修改产品属性":
                        exportExcelVoByAccomplish.setXiugaichanpinshuxing(exportExcelVoByAccomplish.getXiugaichanpinshuxing() + 1);
                        break;
                    case "移机不改号":
                        exportExcelVoByAccomplish.setYijibugaihao(exportExcelVoByAccomplish.getYijibugaihao() + 1);
                        break;
                }
            }
            List<MalfunctionTemplate> malfunctionTemplateList = malfunction.get(stringListEntry.getKey());
            if (malfunctionTemplateList == null || malfunctionTemplateList.isEmpty()) {
                exportExcelVoByAccomplish.setGuzhang(0);
            } else {
                exportExcelVoByAccomplish.setGuzhang(malfunctionTemplateList.size());
            }

            int count = exportExcelVoByAccomplish.getYijibugaihao() + exportExcelVoByAccomplish.getGaisulv() + exportExcelVoByAccomplish.getXinzhuang()
                    + exportExcelVoByAccomplish.getXiugaichanpinshuxing() + exportExcelVoByAccomplish.getGuzhang();
            exportExcelVoByAccomplish.setCount(count);
            result.add(exportExcelVoByAccomplish);
            malfunction.remove(stringListEntry.getKey());
        }

        if (!malfunction.isEmpty()) {
            // 新装的人名都统计好了， 并且都移除了元素， malfunction 集合中剩下的就是没有被统计的人， 再次进行统计
            for (Map.Entry<String, List<MalfunctionTemplate>> stringListEntry : malfunction.entrySet()) {
                ExportExcelVoByAccomplish exportExcelVoByAccomplish = new ExportExcelVoByAccomplish();
                exportExcelVoByAccomplish.setProcessPerson(stringListEntry.getKey());
                List<MalfunctionTemplate> value = stringListEntry.getValue();
                exportExcelVoByAccomplish.setGuzhang(value.size());
                int count = exportExcelVoByAccomplish.getYijibugaihao() + exportExcelVoByAccomplish.getXinzhuang()
                        + exportExcelVoByAccomplish.getXiugaichanpinshuxing() + exportExcelVoByAccomplish.getGuzhang();
                exportExcelVoByAccomplish.setCount(count);
                result.add(exportExcelVoByAccomplish);
            }
        }
        return result;
    }

    private List<MalfunctionTemplate> processMalfunctionUnfinishedData(List<MalfunctionTemplate> malfunctionUnfinishedList) {
        return malfunctionUnfinishedList;
    }

    private List<InstallUnfinished> processInstallUnfinishedData(List<InstallUnfinished> installUnfinishedList) {
        List<InstallUnfinished> oneResult = installUnfinishedList.stream()
                .filter(a -> !a.getThisProcessPerson().equals("张丹"))
                .collect(Collectors.toList());
        List<InstallUnfinished> twoResult = oneResult.stream()
                .filter(a -> !a.getThisProcessPerson().equals("顾孝恒"))
                .collect(Collectors.toList());
//        List<InstallUnfinished> threeResult = twoResult.stream().filter(a -> !a.getType().equals("改速率"))
//                .collect(Collectors.toList());
        return twoResult.stream().filter(a -> !a.getType().equals("拆机"))
                .collect(Collectors.toList());
    }

    private List<MalfunctionTemplate> processMalfunctionAccomplishData(List<MalfunctionTemplate> malfunctionAccomplishList) {
        List<MalfunctionTemplate> result = new ArrayList<>();
        for (MalfunctionTemplate malfunctionTemplate : malfunctionAccomplishList) {
            // 获取昨天的年月日
            DateTime yesterday = DateUtil.yesterday();
            Date jdkDate = yesterday.toJdkDate();
            String yesterdayStr = DateUtil.format(jdkDate, "yyyy-MM-dd");
            Date deadlineTime = malfunctionTemplate.getDeadlineTime();
            String taskOverTimeFormat = DateUtil.format(deadlineTime, "yyyy-MM-dd");
            if (yesterdayStr.equals(taskOverTimeFormat)) {
                result.add(malfunctionTemplate);
            }
        }
        return result;
    }

    private List<InstallAccomplish> processInstallAccomplishData(List<InstallAccomplish> installAccomplishList) {
        List<InstallAccomplish> resultOne = new ArrayList<>();
        List<InstallAccomplish> result = new ArrayList<>();
        /**
         * 新装：
         * 包含宽带 -> 宽带
         * 商务宽带 -> 宽带
         * 包含IPTV -> 其它（IPTV，固话）
         * 包含电话 -> 其它（IPTV，固话）
         * 智能家居 -> 智能家居
         * 全屋WIFI -> 全屋WIFI
         */
        List<InstallAccomplish> r = installAccomplishList.stream().filter(a -> !a.getType().contains("拆机")).collect(Collectors.toList());
        // 筛选出来昨天的数据
        for (InstallAccomplish installAccomplish : r) {
            // 获取昨天的年月日
            DateTime yesterday = DateUtil.yesterday();
            Date jdkDate = yesterday.toJdkDate();
            String yesterdayStr = DateUtil.format(jdkDate, "yyyy-MM-dd");
            Date taskOverTime = installAccomplish.getTaskOverTime();
            String taskOverTimeFormat = DateUtil.format(taskOverTime, "yyyy-MM-dd");
            if (yesterdayStr.equals(taskOverTimeFormat)) {
                if (!"张丹".equals(installAccomplish.getThisProcessPerson()) && !"顾孝恒".equals(installAccomplish.getThisProcessPerson())) {
                    resultOne.add(installAccomplish);
                }
            }
        }
        for (InstallAccomplish installAccomplish : resultOne) {
            String product = installAccomplish.getProduct().trim();
            if (product.contains("宽带") || product.contains("商务专线")) {
                installAccomplish.setProduct("宽带");
            } else if (product.contains("IPTV") || product.contains("电话")) {
                // 包含IPTV 或者 包含电话
                installAccomplish.setProduct("其他（IPTV+电视）");
            } else if (product.contains("智能家居")) {
                installAccomplish.setProduct("智能家居");
            } else if (product.contains("全屋WIFI")) {
                installAccomplish.setProduct("全屋WIFI");
            }
            result.add(installAccomplish);
        }

        return result;
    }

    private DataRoot processData(List<File> files) {
        List<MalfunctionTemplate> malfunctionAccomplishList = new ArrayList<>();
        List<MalfunctionTemplate> malfunctionUnfinishedList = new ArrayList<>();
        List<InstallAccomplish> installAccomplishList = new ArrayList<>();
        List<InstallUnfinished> installUnfinishedList = new ArrayList<>();
        List<Substation> substationList = new ArrayList<>();
        for (File file : files) {
            if ("故障竣工.xls".equals(file.getName())) {
                malfunctionAccomplishList = EasyExcel.read(file, MalfunctionTemplate.class, new MalfunctionTemplateListener()).sheet().doReadSync();
            }
            if ("新装竣工.xls".equals(file.getName())) {
                installAccomplishList = EasyExcel.read(file, InstallAccomplish.class, new InstallAccomplishListener()).sheet().doReadSync();
            }
            if ("故障在途.xls".equals(file.getName())) {
                malfunctionUnfinishedList = EasyExcel.read(file, MalfunctionTemplate.class, new MalfunctionTemplateListener()).sheet().doReadSync();
            }
            if ("新装在途.xls".equals(file.getName())) {
                installUnfinishedList = EasyExcel.read(file, InstallUnfinished.class, new InstallUnfinishedListener()).sheet().doReadSync();
            }
            if ("支局对应关系.xls".equals(file.getName())) {
                substationList = EasyExcel.read(file, Substation.class, new SubstationListener()).sheet().doReadSync();
            }
        }
        System.out.println("数据分析：故障竣工数量：" + malfunctionAccomplishList.size());
        System.out.println("数据分析：新装竣工数量：" + installAccomplishList.size());
        System.out.println("数据分析：故障在途数量：" + malfunctionUnfinishedList.size());
        System.out.println("数据分析：新装在途数量：" + installUnfinishedList.size());
        System.out.println("数据分析：支局对照表数量：" + substationList.size());
        DataRoot dataRoot = new DataRoot();
        dataRoot.setMalfunctionAccomplishList(malfunctionAccomplishList);
        dataRoot.setInstallAccomplishList(installAccomplishList);
        dataRoot.setMalfunctionUnfinishedList(malfunctionUnfinishedList);
        dataRoot.setInstallUnfinishedList(installUnfinishedList);
        dataRoot.setSubstationList(substationList);
        return dataRoot;
    }

    public static void main(String[] args) {
        launch(args);
    }
}
